package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.MyCard
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IMyCardView
import de.baumann.browser.model.CardModel

class MyCardPresenter : BasePresenter<IMyCardView>() {
    fun getMyCard() {
        CardModel().getMyCard()
                .subscribe(object : OdinObserver<MyCard>(view) {
                    override fun onSuccess(data: MyCard) {
                        view.let {
                            view.setActiveStatus(data.activeStatus)

                            if(data.activeStatus == 0){
                                val time = data.lastTime
                                if (time.isNotEmpty()) {
                                    val timeArr = time.split(",")
                                    if (timeArr.size >= 3) {
                                        view.setLastTime(timeArr[0], timeArr[1], timeArr[2])
                                    }
                                }
                            }

//                            view.setCardType(data.cardType)
                            view.setCardName(data.cardName)
                            view.setCardPowers(data.cardPower!!)
                            view.setCardPowerDescs(data.powerDescs!!)
                            view.setHash(data.totalHash, data.lastHash)
                        }
                    }
                })
    }
}